package gov.mogaha.ntis.cmm.mob.view;

import gov.mogaha.ntis.cmm.mob.R;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class AddressDistrictListViewAdapter extends AddressListViewAdapter {
	private final Context context;
	private final int layoutResource;
	
	
	
	public AddressDistrictListViewAdapter(Context context, int layoutResource, List<ArrayList<String>> objects) {
		super(context, layoutResource, objects);
		
		this.context = context;
		this.layoutResource = layoutResource;
	}
	
	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		Wrapper wrapper;
		
		
		//인플레이트
		if (view == null) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(layoutResource, null);
			
			wrapper = new Wrapper(view);
			view.setTag(wrapper);
			
		} else {
			wrapper = (Wrapper) view.getTag();
		}
		
		
		//데이터
		ArrayList<String> addrData= getItem(position);
		if (addrData  != null) {
			TextView[] textItems = new TextView[2];
			textItems[0] = wrapper.getText1();
			textItems[1] = wrapper.getText2();
			
			for (int i=0; i<addrData.size(); i++) {
				textItems[i].setText(addrData.get(i));
			}
		}
		
		
		return view;
	}
	
	
	
	private class Wrapper {
		private final View base;
		private TextView[] textView;
		
		public Wrapper(View base) {
			this.base = base;
			textView = new TextView[2];
		}

		public TextView getText1() {
			if (textView[0] == null) textView[0] = (TextView) base.findViewById(R.id.text_DistAddrList_Item1);
			return textView[0];
		}
		
		public TextView getText2() {
			if (textView[1] == null) textView[1] = (TextView) base.findViewById(R.id.text_DistAddrList_Item2);
			return textView[1];
		}
	}
}














